package com.situ.mymall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.mymall.mapper.OrderMapper;
import com.situ.mymall.pojo.entity.Order;
import com.situ.mymall.pojo.query.OrderQuery;
import com.situ.mymall.service.IOrderService;
import com.situ.mymall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements IOrderService {

    @Autowired
    private OrderMapper orderMapper;


    @Override
    public PageResult selectByPage(OrderQuery orderQuery) {
        PageHelper.startPage(orderQuery.getPage(), orderQuery.getLimit());
        List<Order> list = orderMapper.selectByPage(orderQuery);
        PageInfo pageInfo = new PageInfo(list);
        int totalCount = (int) pageInfo.getTotal();

        return PageResult.ok(totalCount,list);
    }

    @Override
    public Order selectById(Long orderNo) {
        return orderMapper.selectById(orderNo);
    }

    @Override
    public void add(Order order) {
        orderMapper.insertSelective(order);
    }

    @Override
    public void deleteById(Integer id) {
        orderMapper.deleteByPrimaryKey(Long.valueOf(id));
    }

    @Override
    public void deleteAll(Integer[] ids) {
        orderMapper.deleteAll(ids);
    }

    @Override
    public void update(Order order) {
        orderMapper.updateByPrimaryKeySelective(order);
    }
}
